package com.atguigu3.common_algorithm.exer3;

/**
 * @author lhl
 * @date 2025/3/31 10:43
 */
public class YangHuiTest {
    public static void main(String[] args) {
        //1.创建二维数据
        int[][] yangHui = new int[10][];

        //2.使用循环结构，外层结构初始化赋值
        for (int i = 0; i < yangHui.length; i++) {
            yangHui[i] = new int[i + 1];
            //给首末元素进行赋值
            yangHui[i][0] = yangHui[i][yangHui[i].length - 1]= 1;
            //给非首末元素进行赋值(j从每行第二个元素开始，到倒数第二个元素结束)
            for (int j = 1; j < yangHui[i].length - 1; j++) {
                yangHui[i][j]= yangHui[i-1][j-1] + yangHui[i-1][j];
            }
        }

        //遍历二维数组
        for (int i = 0; i < yangHui.length; i++) {
            for (int j = 0; j < yangHui[i].length; j++) {
                System.out.print(yangHui[i][j] + "\t");
            }
            System.out.println();
        }
    }
}
